package com.ruoyi.web.controller.ucenter.api;

import com.ruoyi.common.annotation.Check;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.model.auth.AuthContextHolder;
import com.ruoyi.model.user.UserCheck;
import com.ruoyi.ucenter.service.IUserCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/u-apply")
@Api(tags = "组织申请")
public class UserCheckApiController extends BaseController {
    @Autowired
    private IUserCheckService userCheckService;
    /**
     * 新增申请组织
     */
    @Check
    @ApiOperation(value = "用户新增组织申请")
    @PostMapping
    public AjaxResult add(@RequestBody UserCheck userCheck)
    {
        if (userCheck.getStatus().equals("1")){
            userCheck.setStatus("1");
            userCheck.setAddTime(DateUtils.getNowDate());
        }else{
            userCheck.setStatus("0");
        }
        userCheck.setUserId(AuthContextHolder.getUserId());
        return toAjax(userCheckService.insertUserCheck(userCheck));
    }

    /**
     * 修改申请组织
     */
    @Check
    @ApiOperation(value = "用户修改组织申请")
    @PutMapping
    public AjaxResult edit(@RequestBody UserCheck userCheck)
    {
        if (userCheck.getStatus().equals("1")){
            userCheck.setStatus("1");
            userCheck.setAddTime(DateUtils.getNowDate());
        }else{
            userCheck.setStatus("0");
        }
        userCheck.setUserId(AuthContextHolder.getUserId());
        return toAjax(userCheckService.updateUserCheck(userCheck));
    }
    /**
     * 获取申请组织详细信息
     */
    @Check
    @ApiOperation(value = "用户获取组织申请")
    @GetMapping
    public AjaxResult getInfo()
    {
        String userId = AuthContextHolder.getUserId();
        return success(userCheckService.selectUserCheckByUserId(userId));
    }
}
